{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "TTCTTGGGAACTGCTGCAGTCTACCAGGTACGTCTACAGTTTGATGTTACTTAAGGAAGCT\n",
      "[[0.3481252914345408, 0.4569141883306061, 0.4786719677098192, 0.8267964377772282, 0.6527342027435237], [-0.3916392074587034, -0.587459221871621, -0.4351547662171295, -0.47867032497555567, -0.6309747806300471, -0.6744903393884732, -1.0878881475935214, -1.4577703970401434, -1.3924970589025043, -1.588317073315422], [-1.4577703970401434, -1.6753481908322743, -1.4795281764193566, 0.087031938883984, 0.6527342027435237, 0.9791008934317197, 0.8485542171564413, 0.8050386583980151, 0.7180075408811629, 0.8050386583980151], [0.8267964377772282, 0.6527342027435237, 0.6309764233643106, 0.761523099639589, 0.7397653202603759], [0.9138275552940804, 0.8920697759148674, 1.5012875985328331, 1.414256481015981, 1.3707409222575548, 1.2619520253614895, 8.213671317493025e-07, -0.19581919304578582, -0.17406141366657277, -0.23933475180421196], [0.13054749764241014, 0.7397653202603759, 0.8050386583980151, 0.2828519532969016, 0.9791008934317197], [0.8703119965356543, 0.7397653202603759, 0.7832808790188021, 0.761523099639589, 0.8485542171564413], [0.8703119965356543, 0.5439453058474584, 0.9791008934317197, 0.8267964377772282, 0.8703119965356543, 0.7832808790188021, 0.8050386583980151, 0.8703119965356543, 0.5657030852266715, 0.6309764233643106, 0.8920697759148674, 0.8485542171564413, 0.5874608646058845, 0.7180075408811629, 0.6527342027435237, 0.761523099639589, 0.6527342027435237, 0.8050386583980151, 0.6092186439850975, 0.8485542171564413, 0.8703119965356543, 0.8485542171564413, 0.3916408501929669, 0.6092186439850975, 0.4786719677098192, 0.5657030852266715, 0.6962497615019498, 0.8703119965356543, 0.8050386583980151, 0.7180075408811629, 0.7397653202603759, 0.7397653202603759, 0.6527342027435237, 0.6092186439850975, 0.6092186439850975, 0.5439453058474584, 0.7180075408811629, 0.4569141883306061, 0.6744919821227368, 0.6309764233643106], [0.4569141883306061, 0.5221875264682453, 0.435156408951393, -0.23933475180421196, -0.0870302961497205, -0.021756958012081315, -0.2828503105626381, -0.13054585490814663, -0.3481236487002773, -0.6527325600092602], [-1.0008570300766693, -0.8267947950429647, -0.5439436631131949, -0.7397636775261124, -0.6962481187676863, -0.7832792362845385, -0.7832792362845385, -0.9138259125598169, -0.8050370156637516, -0.609217001250834], [-0.8267947950429647, -0.9790992506974562, -1.3272237207648652, -1.566559293936209, -1.4577703970401434, -1.1749192651103737, -1.3489815001440781, -1.566559293936209, -1.631832632073848, -1.4360126176609305], [-1.4360126176609305, -1.631832632073848, -1.4360126176609305, -1.3272237207648652, -1.631832632073848, -1.8711682052451917, -1.5012859557985696, -1.4142548382817175, -2.654448262896862, -1.4577703970401434, -1.4360126176609305, -1.1966770444895867, -1.261950382627226, -1.3707392795232913, -1.4360126176609305, -1.3272237207648652, -1.4360126176609305, -1.3489815001440781, -1.3054659413856522, -0.8485525744221778, -0.6527325600092602, -0.4133969868379165, -0.5004281043547687, -0.4569125455963426, -0.4351547662171295, -0.3916392074587034, -0.4133969868379165, -0.565701442492408, -0.3481236487002773, -0.2175769724249989], [-0.2175769724249989, 0.30460973267611463, 0.04351638012555788, 0.30460973267611463, 0.4569141883306061, 0.41339862957218, 0.4786719677098192, 0.435156408951393, 0.4786719677098192, 0.8920697759148674], [1.0878897903277849, 1.1531631284654242, 0.7832808790188021, 0.8485542171564413, 0.8267964377772282], [0.7832808790188021, 0.5221875264682453, 0.8267964377772282, 0.3698830708137538, -0.04351473739129438], [-0.3916392074587034, -0.04351473739129438, -0.2175769724249989, -0.4351547662171295, 0.04351638012555788, -0.1523036342873597, 0.087031938883984, 0.13054749764241014, 0.10878971826319707, 0.13054749764241014], [8.213671317493025e-07, 0.30460973267611463, 0.8267964377772282, 0.9138275552940804, 1.0008586728109328], [0.6962497615019498, 0.7397653202603759, 0.7397653202603759, 0.6527342027435237, 0.7397653202603759], [0.6527342027435237, 0.5221875264682453, 0.4786719677098192, -0.10878807552893358, 0.10878971826319707, 0.021758600746344812, -0.13054585490814663, -0.04351473739129438, -0.261092531183425, 0.06527415950477095], [0.1523052770216232, 0.761523099639589, 0.7397653202603759, 0.4786719677098192, 0.8050386583980151, 0.5657030852266715, 0.5221875264682453, 0.5004297470890322, 0.19582083578004933, 0.41339862957218, 0.3916408501929669, 0.5004297470890322, 0.5004297470890322, 0.5221875264682453, 0.5439453058474584], [0.6092186439850975, -0.7615214569053255, -0.8920681331806039, -1.1314037063519475, -1.0443725888350954], [-1.5230437351777828, -1.5230437351777828, -1.6753481908322743, -1.4360126176609305, -1.4577703970401434, -1.3924970589025043, -1.3707392795232913, -1.8276526464867657, -1.4360126176609305, -1.3489815001440781], [-0.8920681331806039, 1.784138730462603, 1.6100764954288984, 1.5665609366704725, 1.8929276273586684, 1.8929276273586684, 1.457772039774407, 1.6100764954288984, 1.8711698479794552, 1.8929276273586684], [1.5448031572912593, 1.8711698479794552, 1.6971076129457507, 1.1749209078446372, 0.5221875264682453, 0.21757861515926238, 0.10878971826319707, 0.21757861515926238, 0.4569141883306061, 1.0226164521901457], [0.9138275552940804, 1.1531631284654242, 1.0878897903277849, 1.3707409222575548, 1.0878897903277849, 1.2184364666030634, 1.109647569706998, 1.1749209078446372, 1.1966786872238502, 0.8920697759148674], [0.8920697759148674, 1.044374231569359, 0.30460973267611463, 0.2828519532969016, 0.30460973267611463], [0.3698830708137538, 1.109647569706998, 1.2619520253614895, 1.3924987016367678, 1.2184364666030634, 1.3489831428783416, 1.3272253634991287, 1.3489831428783416, 1.2837098047407025, 1.2619520253614895], [0.9573431140525066, 0.8703119965356543, 0.761523099639589, 0.8485542171564413, 0.8267964377772282], [0.7180075408811629, 0.6092186439850975, 8.213671317493025e-07, -0.19581919304578582, 0.06527415950477095], [-0.261092531183425, -0.261092531183425, -0.5221858837339818, -0.8267947950429647, -1.0878881475935214], [-1.1749192651103737, -1.0878881475935214, -1.2401926032480128, -1.1749192651103737, -1.0878881475935214, -0.9573414713182431, -1.1966770444895867, -1.3054659413856522, -1.2401926032480128, -1.1531614857311607], [1.5012875985328331, 1.1966786872238502, 1.1966786872238502, 1.1749209078446372, 0.6527342027435237], [8.213671317493025e-07, 0.06527415950477095, -0.17406141366657277, -0.10878807552893358, 0.3916408501929669], [0.3481252914345408, -0.3046080899418511, -0.7397636775261124, 0.19582083578004933, 0.021758600746344812, 0.04351638012555788, -1.2401926032480128, -1.261950382627226, -1.2401926032480128, -1.5230437351777828, -1.1314037063519475, -1.4360126176609305, -1.3054659413856522, -1.3054659413856522, -1.4577703970401434], [-1.283708162006439, -1.3272237207648652, -1.1966770444895867, -1.3489815001440781, -1.1966770444895867, -1.3272237207648652, -1.261950382627226, -0.6962481187676863, 1.8276542892210292, 1.6971076129457507], [1.8711698479794552, 1.6753498335665378, 1.6971076129457507, 0.7397653202603759, 0.04351638012555788], [0.2610941739176885, 0.4569141883306061, 0.30460973267611463, 0.21757861515926238, 0.3916408501929669, 0.23933639453847547, 0.5221875264682453, 0.10878971826319707, 0.5221875264682453, 0.13054749764241014], [0.435156408951393, 0.4569141883306061, 0.4569141883306061, 1.066132010948572, 1.1531631284654242, 1.2837098047407025, 0.8485542171564413, 0.8485542171564413, 0.3481252914345408, 0.3698830708137538], [0.021758600746344812, 0.6527342027435237, 0.41339862957218, 0.41339862957218, 0.9573431140525066], [1.0008586728109328, 0.8703119965356543, 0.9355853346732935, 0.761523099639589, 0.8267964377772282, 0.8267964377772282, -0.13054585490814663, -0.7397636775261124, -0.8703103538013908, -0.8050370156637516], [-0.7397636775261124, -0.5439436631131949, -1.0008570300766693, -0.565701442492408, -0.7397636775261124, -0.7397636775261124, -0.6744903393884732, -0.8267947950429647, -1.0226148094558822, -0.609217001250834, -0.6309747806300471, -0.8267947950429647, -0.7180058981468994, -0.8050370156637516, -0.9138259125598169, -0.6962481187676863, -0.7397636775261124, -0.8267947950429647, -2.0887459990373225, -1.8929259846244049], [-2.0234726608996834, -1.9799571021412572, -2.045230440278896, -1.8929259846244049, -1.9146837640036178, -2.00171488152047, -1.936441543382831, -1.958199322762044, -2.3715971309670922, -1.6971059702114872, -1.936441543382831, -1.8711682052451917, -1.8929259846244049, -1.936441543382831, -2.0887459990373225, -1.6753481908322743, -2.00171488152047, -2.00171488152047, -1.9799571021412572, -1.9799571021412572, -2.1322615577957484, -2.0887459990373225, -1.8711682052451917, -2.045230440278896, -1.958199322762044, -1.958199322762044, -1.958199322762044, -2.1975348959333876, -1.958199322762044, -2.241050454691814, -1.7841370877283396, -1.8711682052451917, -1.936441543382831, -2.1105037784165357, -1.958199322762044, -1.7406215289699134, -2.2192926753126008, -2.045230440278896, -1.9146837640036178, -1.8058948671075525], [-1.9799571021412572, -1.8058948671075525, -2.1322615577957484, -0.021756958012081315, 0.30460973267611463, 0.21757861515926238, 0.4786719677098192, 0.8485542171564413, 0.8485542171564413, 0.6744919821227368], [0.7397653202603759, 0.8050386583980151, 0.6527342027435237, 0.6092186439850975, 0.30460973267611463], [0.8267964377772282, 0.8485542171564413, 0.6962497615019498, 0.7832808790188021, 0.761523099639589, 0.761523099639589, 0.8050386583980151, 0.9138275552940804, 0.761523099639589, 0.761523099639589, 0.7180075408811629, 0.8050386583980151, 0.6527342027435237, 0.6092186439850975, 0.6309764233643106, 0.8703119965356543, 1.0008586728109328, 0.6962497615019498, 0.6962497615019498, 0.6744919821227368, 0.761523099639589, 0.41339862957218, 0.4786719677098192, 0.8703119965356543, 0.4569141883306061], [0.30460973267611463, -1.0226148094558822, -1.1314037063519475, -1.1749192651103737, -1.2401926032480128, -1.0878881475935214, -1.0443725888350954, -1.0878881475935214, -0.8920681331806039, -1.0878881475935214, -0.93558369193903, -1.3924970589025043, -0.9573414713182431, -1.0443725888350954, -0.9573414713182431, -1.0443725888350954, -0.9790992506974562, -0.8920681331806039, -1.0878881475935214, -1.1749192651103737], [-1.1096459269727346, -1.2184348238687999, -1.3054659413856522, -1.1966770444895867, -1.1096459269727346, -1.2401926032480128, -1.1096459269727346, -1.2401926032480128, -1.1314037063519475, -1.0878881475935214, -0.8050370156637516, -0.9573414713182431, -1.1531614857311607, -1.0878881475935214, -1.0008570300766693, -1.0878881475935214, -1.283708162006439, -1.3272237207648652, -1.0008570300766693, -1.1096459269727346], [0.3916408501929669, 1.5448031572912593, 1.6535920541873246, 1.3272253634991287, 1.6971076129457507, 1.4795298191536201, 1.3272253634991287, 1.5665609366704725, 1.3489831428783416, 1.5448031572912593], [1.2619520253614895, 1.4795298191536201, 0.8485542171564413, 0.6962497615019498, -0.9573414713182431, -1.0008570300766693, -0.8920681331806039, -1.283708162006439, -0.7832792362845385, 0.5004297470890322], [0.6527342027435237, 0.5657030852266715, 0.7397653202603759, 0.7397653202603759, 0.3481252914345408, 0.6527342027435237, 0.4569141883306061, 0.8920697759148674, 0.5657030852266715, 0.6527342027435237], [0.6962497615019498, 0.8267964377772282, 0.6962497615019498, 0.761523099639589, 0.435156408951393, 0.9791008934317197, 0.8920697759148674, 0.5221875264682453, 0.7397653202603759, 0.4569141883306061], [-0.1523036342873597, -0.3916392074587034, -0.0870302961497205, -0.261092531183425, -0.2175769724249989, -0.10878807552893358, -0.2175769724249989, -0.3916392074587034, -0.17406141366657277, -0.23933475180421196], [-0.13054585490814663, -0.04351473739129438, -0.17406141366657277, -0.06527251677050744, -0.3046080899418511, -0.3481236487002773, -0.17406141366657277, -0.4351547662171295, -0.19581919304578582, -0.0870302961497205], [0.9138275552940804, 1.1966786872238502, 1.0008586728109328, 0.6309764233643106, 0.9138275552940804], [1.2837098047407025, 1.0008586728109328, 0.9355853346732935, 0.8485542171564413, 0.9138275552940804, 0.7180075408811629, 0.9791008934317197, 1.044374231569359, 1.0008586728109328, 0.9791008934317197], [1.0008586728109328, 0.8920697759148674, 0.8050386583980151, 0.1523052770216232, -0.04351473739129438, 0.2828519532969016, -0.04351473739129438, 0.04351638012555788, -0.17406141366657277, -0.06527251677050744, -0.13054585490814663, -0.23933475180421196, -0.13054585490814663, -0.3046080899418511, -0.23933475180421196], [-0.1523036342873597, -0.13054585490814663, -0.4133969868379165, -0.04351473739129438, -0.2175769724249989], [-0.04351473739129438, -0.17406141366657277, -0.3481236487002773, -0.2828503105626381, -0.19581919304578582, -0.3263658693210642, -0.19581919304578582, -0.1523036342873597, -0.47867032497555567, -0.7832792362845385, -0.6309747806300471, -0.609217001250834, -0.7397636775261124, -0.4133969868379165, -0.6527325600092602], [-1.0008570300766693, -1.1531614857311607, -1.0878881475935214, -1.2184348238687999, -1.1749192651103737], [-1.0443725888350954, -0.8920681331806039, -0.6962481187676863, -0.9790992506974562, -1.0878881475935214, -1.0878881475935214, -1.0878881475935214, -1.261950382627226, -1.5230437351777828, -1.1314037063519475, -1.1314037063519475, -0.8267947950429647, -1.1314037063519475, -1.1749192651103737, -1.1749192651103737, -1.3272237207648652, -1.1749192651103737, -0.9790992506974562, -1.0226148094558822, -0.9138259125598169, -0.8920681331806039, -1.0443725888350954, -0.9138259125598169, -0.9790992506974562, -1.1314037063519475, -0.93558369193903, -1.1749192651103737, -0.9790992506974562, -0.7832792362845385, -0.8920681331806039], [-0.8267947950429647, -0.9573414713182431, -0.9790992506974562, -0.8267947950429647, -0.8703103538013908, -0.8920681331806039, -0.8050370156637516, -0.8267947950429647, -0.565701442492408, -0.6962481187676863]]\n"
     ]
    }
   ],
   "source": [
    "input='/home/xiaoyifu/demo.6reads.tsv'\n",
    "pos=5256\n",
    "with open(input,'r') as rb:\n",
    "    for line in rb:\n",
    "        words=line.strip().split('\\t')\n",
    "        readid=words[0]\n",
    "        if readid!='cf847b3e-9d0c-462d-b1cf-49cc67911436':\n",
    "            continue\n",
    "        seq=words[3]\n",
    "        signals = words[4]\n",
    "        signals_event = [[int(num) for num in x.split(',')] if len(x) > 0 else [] for x in signals.split(';')]\n",
    "        shift_dacs_to_pa, scale_dacs_to_pa, shift_pa_to_norm, scale_pa_to_norm = [float(x) for x in words[11:15]]\n",
    "        shift=(shift_pa_to_norm/scale_dacs_to_pa)- shift_dacs_to_pa\n",
    "        scale=scale_pa_to_norm/scale_dacs_to_pa\n",
    "        norm_events = [[(reading-shift)/scale for reading in event] for event in signals_event]\n",
    "        print(seq[pos-30:pos+30+ 1])\n",
    "        print(norm_events[pos-30:pos+30+ 1])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "72\n"
     ]
    }
   ],
   "source": [
    "input='/home/xiaoyifu/demo.6reads.tsv'\n",
    "num=0\n",
    "with open(input,'r') as rb:\n",
    "    for line in rb:\n",
    "        words=line.strip().split('\\t')\n",
    "        seq=words[3]\n",
    "        pos=words[5].split(',')\n",
    "        rpos=words[-1].split(',')\n",
    "        num+=len(pos)\n",
    "        bs=words[-2].split(',')\n",
    "        for i in range(len(pos)):\n",
    "            p=int(pos[i])\n",
    "            rp=rpos[i]\n",
    "            b=bs[i]\n",
    "            if b!='100.0' and b!='0.0':\n",
    "                num-=1\n",
    "                continue\n",
    "            if rp=='-1':\n",
    "                num-=1\n",
    "                print('no ref')\n",
    "                continue\n",
    "            if b=='-1':\n",
    "                num-=1\n",
    "                print('no bs')\n",
    "                continue\n",
    "            if p>len(seq)-30 or p<30:\n",
    "                num-=1\n",
    "print(num)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "deepsignalpenv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.17"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
